<template>
  <div>
    <el-form ref="optForm" :model="pointForm" label-width="90px">
      <div class="ledgerTitle">疑点信息</div>
      <el-row>
        <el-col :span="6">
          <el-form-item label="项目名称:" prop="projectName">
            {{pointForm.projectName}}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="140px" label="疑点编号:" prop="pointCode">
            {{pointForm.pointCode}}
          </el-form-item>
        </el-col>
<!--        <el-col :span="6">-->
<!--          <el-form-item label="是否落实:">-->
<!--            {{pointForm.fix | yesOrNo}}-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="6">-->
<!--          <el-form-item label="形成发现:">-->
<!--            {{pointForm.discovery | yesOrNo}}-->
<!--          </el-form-item>-->
<!--        </el-col>-->
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="疑点描述:">
            <pre class="pre-style">{{ pointForm.pointDesc }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="ledgerTitle">基本信息</div>
    <el-form ref="optForm" :model="form" label-width="90px">
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="审计事项:" prop="auditMatter">
            <pre class="pre-style">{{ form.auditMatter }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="审计事项摘要:" prop="auditPurpose">
            <pre class="pre-style">{{ form.auditMatterAbstract }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="定性及依据:" prop="lawId">
            <pre class="pre-style">{{ form.lawContent }}</pre>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle" v-if="form.status >= 3">被审计单位答复</div>
      <el-row>
        <el-col>
          <el-form-item label-width="140px" label="证据提供单位意见:" prop="auditPurpose" v-if="form.status >= 3">
            <pre class="pre-style">{{ form.providerOpinion }}</pre>
          </el-form-item>
        </el-col>
        <el-col>
          <el-form-item label-width="140px" label="附件:" v-if="form.wordFile">
            <el-upload
              class="upload-demo"
              action="/admin/sys-file/upload"
              :file-list="fileList"
              :show-file-list="true"
              :on-preview="handlePreview"
              v-if="form.wordFile">
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle" v-if="form.status >= 3">审计取证单文书</div>
      <el-row >
        <el-col :span="24">
          <el-form-item label-width="140px" label="审计取证单:" prop="projectName" v-if="form.status >= 3">
            <web-document :form-data="form" readWord="view" :pageType="'evidence'" @createWordFile="wordFileHandle" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>

import {getEvidence} from "@/api/adis/execute/evidence";
import {getPoint} from "@/api/adis/execute/point";
import WebDocument from '@/components/form/webDocument.vue';

export default {
  name: 'AuditEvidenceView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  components: {
    WebDocument
  },
  dictTypes: ['audit_type'],
  data() {
    return {
      pointForm: {},
      form:{},
      fileList:[],
      lawList:[
        {value: 1729795756551872513,label: '偷税漏税'},
        {value: 1729795756551876777,label: '使劲罚'}],
    }
  },
  watch: {
    id: {
      handler(val){
        if (val){
          getEvidence(val).then((res) => {
            if (res.data.data !== null){
              this.handleEvidenceResponse(res.data.data)
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          });
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val) {
        if (val) {
          this.handleEvidenceResponse(val)
        }
      },deep: true, immediate: true
    }
  },
  methods: {
    handleEvidenceResponse(val) {
      this.$set(this, "form", val);
      let pointForm = {};
      pointForm.pointCode = this.form.pointCode
      pointForm.projectName = this.form.projectName
      pointForm.fix = this.form.fix
      pointForm.discovery = this.form.discovery
      pointForm.pointDesc = this.form.pointDesc
      this.pointForm = pointForm
      this.fileList = val.attachments;
      this.fileList.forEach((item) =>{
        item.name = item.fileName;
      })
    },
    wordFileHandle(e) {
      this.$set(this.form, "wordFile", e.wordFile);
      this.$set(this.form, "evidenceId", e.id);
    },
    handlePreview(file) {
      const a = document.createElement('a');
      let url = file.url ? file.url : file.response.data.url;
      console.log(url);      // let fileName = '你想要的文件名.docx'; // 这里设置你想要的文件名，包括扩展名
      a.setAttribute('download', file.name);
      a.setAttribute('href', url);
      a.click();
    },
  }
}
</script>
